console.time('handleRoute')

let pageData = require('@/pages.json')
console.warn('routes.js 页面处理路由', pageData)
let pageInfo = pageData.default;


// 获取所有页面路由
var pageConfig = pageInfo || {};
var pages = pageConfig.pages; //pages.json下的页面路由
var tabBar = pageConfig.tabBar; //pages.json下的页面路由
var subPackages = pageConfig.subPackages || []; //pages.json下的分包页面路由



// 主包
var arrRoute = pages.map(v => ({
	type: 'main',//主包
	path: v.path,
	title: v.style.navigationBarTitleText || ''
}))

// 分包
if (subPackages.length) {

	subPackages.forEach(group => {
		let arrRouteSub = group.pages.map(v => ({
			type: 'pkg',//分包
			path: group.root + '/' + v.path,
			title: v.style.navigationBarTitleText || ''
		}))
		
		arrRoute.push(...arrRouteSub)
	})
}


var pageMap = {};
arrRoute.forEach(item => {
	var keyArr = item.path.split('/');
	var key = keyArr[keyArr.length - 1];
	
	if(pageMap[key]) {
		console.warn('重复页面路由', item.path)
	}
	
	pageMap[key] = item.path;
	pageMap[key] = {
		route: item.path,
		title: item.title,
		type: item.type
	};
})


//JSON.stringify(pageMap)
let routePathMap = pageMap;

// tabber 路由
var tabBarList = [
	// 'index',
	// 'my',
];
if (tabBar && tabBar.list) {
	tabBar.list.forEach(v => {
		var keyArr = v.pagePath.split('/')
		var tabBarRoute = keyArr[keyArr.length - 1]
		tabBarList.push(tabBarRoute)
	})
}


console.timeEnd('handleRoute')

export default {
	routePathMap,
	tabBarList,
};